package com.chen.hotel.controller;


import com.chen.hotel.VO.ResultVO;
import com.chen.hotel.exception.HotelException;
import com.chen.hotel.utils.ResultVOUtil;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class MyExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public ResultVO exceptionHandler(Exception e){
        if(e instanceof HotelException){
            return ResultVOUtil.error(((HotelException) e).getCode(), e.getMessage());
        }
        e.printStackTrace();
        return ResultVOUtil.error(500, e.getMessage());
    }
}
